package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.domain.EnterpriseInfo;
import com.blrs.domain.ProductList;
import com.blrs.domain.QualificationSwpplier;
import com.blrs.service.list.IProductListService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;

import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【产品清单】Controller
 * 
 * @author ruoyi
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/product/list")
public class ProductListController extends BaseController
{
    @Autowired
    private IProductListService productListService;

    /**
     * 查询【产品清单】列表
     */
    //@PreAuthorize("@ss.hasPermi('brls:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductList productList)
    {
        startPage();
        List<ProductList> list = productListService.selectProductListList(productList);
        return getDataTable(list);
    }

    /**
     * 导出【产品清单】列表
     */
    //@PreAuthorize("@ss.hasPermi('brls:list:export')")
    @Log(title = "【产品清单】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductList productList)
    {
        List<ProductList> list = productListService.selectProductListList(productList);
        ExcelUtil<ProductList> util = new ExcelUtil<ProductList>(ProductList.class);
        util.exportExcel(response, list, "【产品清单】数据");
    }

    /**
     * 获取【产品清单】详细信息
     */
    //@PreAuthorize("@ss.hasPermi('brls:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(productListService.selectProductListById(id));
    }
    /**
     * 下载管理模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<ProductList> util = new ExcelUtil<>(ProductList.class);
        util.importTemplateExcel(response, "供应商产品清单模板");
    }
    /**
     * 导入企业信息数据
     */
    @Log(title = "导入供应商产品清单", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport, @RequestParam("enterpriseId") String enterpriseId) throws Exception
    {
        ExcelUtil<ProductList> util = new ExcelUtil<>(ProductList.class);
        List<ProductList> list = util.importExcel(file.getInputStream());
        String message = productListService.importExcel(list,enterpriseId);
        return success(message);
    }

    /**
     * 新增【产品清单】
     */
   // @PreAuthorize("@ss.hasPermi('brls:list:add')")
    @Log(title = "【产品清单】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductList productList)
    {
        return toAjax(productListService.insertProductList(productList));
    }

    /**
     * 修改【产品清单】
     */
    //@PreAuthorize("@ss.hasPermi('brls:list:edit')")
    @Log(title = "【产品清单】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductList productList)
    {
        return toAjax(productListService.updateProductList(productList));
    }

    /**
     * 删除【产品清单】
     */
    //@PreAuthorize("@ss.hasPermi('brls:list:remove')")
    @Log(title = "【产品清单】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productListService.deleteProductListByIds(ids));
    }

    /**
     * 查询所有的产品信息以及对应的供应商
     */
    @GetMapping("/productList")
    public TableDataInfo productList(ProductList productList){
        startPage();
        List<ProductList> list =productListService.selectProductListListProductInfo(productList);
        return getDataTable(list);
    }

    /**
//     * 供应商产品统计
//     */
//    @GetMapping("/supplierCount")
//    public  TableDataInfo supplierCount(ProductList productList){
//        startPage();
//        List<ProductList> list = productListService.selectProductListListSupplierCount(productList);
//        return getDataTable(list);
//    }
}
